package com.wswy.wzcx.ui.dialog

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.support.v7.app.AppCompatDialog
import android.util.Log
import android.view.Window
import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTBannerAd
import com.wswy.wzcx.BuildConfig
import com.wswy.wzcx.R
import com.wswy.wzcx.module.ad.AdConfigLoader
import com.wswy.wzcx.module.ad.TTAdManagerHolder
import kotlinx.android.synthetic.main.dialog_home_ad.*

class ExitDialog(private val act:Activity,private val confirmCallback:(()->Unit)?) : AppCompatDialog(act) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        window?.requestFeature(Window.FEATURE_NO_TITLE)

        setContentView(R.layout.dialog_home_ad)


        btn_left.setOnClickListener {
            dismiss()
            confirmCallback?.invoke()
        }
        btn_right.setOnClickListener {
            dismiss()
        }
        loadAd()
    }


    private fun loadAd(){
        val adSlot = AdSlot.Builder()
                .setCodeId("903230896")
                .setSupportDeepLink(true)
                .setImageAcceptedSize(600, 500)
                .build()
        TTAdManagerHolder.getInstance(context.applicationContext)
                .createAdNative(act)
                .loadBannerAd(adSlot,object : TTAdNative.BannerAdListener{
                    override fun onBannerAdLoad(ad: TTBannerAd?) {
                        ad?.bannerView?.let {
                            fl_ad_container.addView(it)
                        }
                    }

                    override fun onError(code: Int, message: String?) {
                        if (BuildConfig.DEBUG){
                            Log.e("ExitDialog", "loadBannerAd --> $code  $message")
                        }
                    }

                })
    }

}